<template>
  <el-container>
    <el-main>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>补签申请</el-breadcrumb-item>
      </el-breadcrumb>

      <!--   表单-->
      <div style="width: 700px;height: 600px ;margin: 20px 0;margin-left: 80px" >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户Id:">
          <el-input v-model="form.userId"></el-input>
        </el-form-item>
        <el-form-item label="会议Id:">
          <el-input v-model="form.meetingId"></el-input>
        </el-form-item>
        <el-form-item label="用户名:">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="签到状态">
          <el-select v-model="form.state" placeholder="默认补签">
            <el-option label="补签" value="补签" onselect="this"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="补签时间:">
          <el-input v-model="form.time"></el-input>
        </el-form-item>
        <el-form-item label="签到方法">
          <el-select v-model="form.method" placeholder="补签">
            <el-option label="补签" value="补签" onselect="this"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="补签原因:">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="margin-left: 50px" @click="quxiao">取消</el-button>
          <el-button type="primary" @click="onSubmit" style="margin-left: 80px">立即申请</el-button>
        </el-form-item>
      </el-form>
      </div>
    </el-main>
  </el-container>
</template>

<script>
  import request from "../../utils/request";

  export default {
    name: "RetroactiveApply",
    data() {
      return {
        form: {
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
          userId:'',
          meetingId:'',
          state: '',
          time: '',
          method: '',
          remark :''
        }
      }
    },
    created() {
      //把浏览器的用户信息提取出来
      var UserJsonStr = sessionStorage.getItem("user")
      //转化为json
      var userEntiy = JSON.parse(UserJsonStr)
      //拿到用户名和对应的Id
      this.form.username = userEntiy.userName
      this.form.userId = userEntiy.userId
      //拿到会议信息
      var MeetingJsonStr = sessionStorage.getItem("meeting")
      //转化为json
      var meetingEntiy = JSON.parse(MeetingJsonStr)
      this.form.meetingId = meetingEntiy.meetingId
      //获得当前时间
      var date = new Date();
      var year = date.getFullYear(); //月份从0~11，所以加一
      var dateArr = [date.getMonth() + 1,date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()];
      for(var i=0;i<dateArr.length;i++){
        if (dateArr[i] >= 1 && dateArr[i] <= 9) {
          dateArr[i] = "0" + dateArr[i];
        }
      }
      //拼接出当前时间
      var strDate = year+'-'+dateArr[0]+'-'+dateArr[1]+' '+dateArr[2]+':'+dateArr[3]+':'+dateArr[4];
      this.form.time = strDate
    },
    methods:{
      onSubmit() {
        request.post("punchCad/saveCard",this.form).then(res=>{
          if (res){
            this.$message.success("补签成功,等待管理员审核！");
            this.$router.push("/1");
          }else {
            this.$message.error("失败，请联系管理员！");
          }
        })
      },
      quxiao(){
        this.$router.push("/1");
      }
    }
  };
</script>
<style scoped lang="less">
</style>
